package com.wswy.wzcx.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.che.libcommon.ui.BaseFragment;
import com.wswy.wzcx.model.DataCenter;
import com.wswy.wzcx.model.home.RouterUtils;
import com.wswy.wzcx.module.base.CBaseFragment;

/**
 * Created by wangduheng26 on 2018/1/23.
 * wangduheng26@gmail.com
 * 控制登录操作
 */

public abstract class ILoginFragment extends CBaseFragment {
    public static final int LOGIN_REQUEST_CODE = 0X0101;
    DataCenter center;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        center = DataCenter.get();
        if (!center.hasLogin()) {
            startActivityForResult(RouterUtils.getLogin(), LOGIN_REQUEST_CODE);
        }else{
            setupPage();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == LOGIN_REQUEST_CODE) {
            if(center!=null&&center.hasLogin()){
                setupPage();
            }else{
                finish();
            }
        }
    }

    public abstract void setupPage();
}
